/* Flash OS Routines (Automagically Generated)
 * Copyright (c) 2020 - 2021 NXP, All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

static const uint32_t DAPLINK_RT1170_flash_prog_blob[] = {
    0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2,
    0x4770ba40, 0x4770ba40, 0x4770bac0, 0x4770bac0, 0x49414770, 0x4449b510, 0x460a483e, 0x493f6008,
    0x44492001, 0xf894f000, 0xd1062800, 0x2001493b, 0xf0004449, 0x2800f878, 0x2001d000, 0x2000bd10,
    0xb5704770, 0x460d4613, 0x4604460a, 0x46184601, 0xf8b2f000, 0xd0012800, 0xbd702000, 0xbd701960,
    0x4f2db5f8, 0x4d2e2600, 0x4634444f, 0x444d1f3f, 0x492a6c6b, 0x43604618, 0x44491982, 0xf0002001,
    0x1c64f86d, 0x2c806038, 0xbdf8dbf2, 0x0107b5f8, 0x093f4e23, 0x444e2400, 0x4628e00d, 0x491f4360,
    0x462b19c2, 0x20014449, 0xf858f000, 0x4449491a, 0x1c641f09, 0x6c756008, 0x46292001, 0xf0000300,
    0x42a0f8a8, 0x4814d8e9, 0x1f004448, 0xbdf86800, 0x0106b570, 0x09364812, 0x6c444448, 0x46214615,
    0xf0004630, 0x2900f896, 0x490cd106, 0x46324623, 0x20014449, 0xf832f000, 0x462b4908, 0x44494632,
    0xf0002001, 0x4904f816, 0x1f094449, 0xbd706008, 0x00004770, 0xc0000005, 0x00000008, 0x00000010,
    0x00000190, 0x22214770, 0x69d20412, 0x685268d2, 0xb4304710, 0x04242421, 0x68e469e4, 0x46a468a4,
    0x4760bc30, 0x04122221, 0x68d269d2, 0x471068d2, 0x041b2321, 0x68db69db, 0x47186a5b, 0x2421b430,
    0x69e40424, 0x692468e4, 0xbc3046a4, 0xb5384760, 0x94009c04, 0x04242421, 0x68e469e4, 0x47a06964,
    0xb430bd38, 0x04242421, 0x68e469e4, 0x46a46a24, 0x4760bc30, 0x04122221, 0x68d269d2, 0x471069d2,
    0x04092121, 0x68c969c9, 0x47086989, 0x04122221, 0x68d269d2, 0x47106b92, 0xb5104603, 0x079b430b,
    0x2a04d10f, 0xc808d30d, 0x1f12c910, 0xd0f842a3, 0xba21ba18, 0xd9014288, 0xbd102001, 0x43c02000,
    0x2a00bd10, 0x07d3d003, 0x1c52d003, 0x2000e007, 0x7803bd10, 0x1c40780c, 0x1b1b1c49, 0x7803d107,
    0x1c40780c, 0x1b1b1c49, 0x1e92d101, 0x4618d1f1, 0x2200bd10, 0x428b0903, 0x0a03d32c, 0xd311428b,
    0x469c2300, 0x4603e04e, 0xd43c430b, 0x08432200, 0xd331428b, 0x428b0903, 0x0a03d31c, 0xd301428b,
    0xe03f4694, 0x428b09c3, 0x01cbd301, 0x41521ac0, 0x428b0983, 0x018bd301, 0x41521ac0, 0x428b0943,
    0x014bd301, 0x41521ac0, 0x428b0903, 0x010bd301, 0x41521ac0, 0x428b08c3, 0x00cbd301, 0x41521ac0,
    0x428b0883, 0x008bd301, 0x41521ac0, 0x428b0843, 0x004bd301, 0x41521ac0, 0xd2001a41, 0x41524601,
    0x47704610, 0x0fcae05d, 0x4249d000, 0xd3001003, 0x40534240, 0x469c2200, 0x428b0903, 0x0a03d32d,
    0xd312428b, 0x018922fc, 0x0a03ba12, 0xd30c428b, 0x11920189, 0xd308428b, 0x11920189, 0xd304428b,
    0xd03a0189, 0xe0001192, 0x09c30989, 0xd301428b, 0x1ac001cb, 0x09834152, 0xd301428b, 0x1ac0018b,
    0x09434152, 0xd301428b, 0x1ac0014b, 0x09034152, 0xd301428b, 0x1ac0010b, 0x08c34152, 0xd301428b,
    0x1ac000cb, 0x08834152, 0xd301428b, 0x1ac0008b, 0xd2d94152, 0x428b0843, 0x004bd301, 0x41521ac0,
    0xd2001a41, 0x46634601, 0x105b4152, 0xd3014610, 0x2b004240, 0x4249d500, 0x46634770, 0xd300105b,
    0xb5014240, 0x46c02000, 0xbd0246c0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
};

// Start address of flash
static const uint32_t flash_start = 0x30000000;
// Size of flash
static const uint32_t flash_size = 0x00800000;

/**
* List of start and size for each size of flash sector - even indexes are start, odd are size
* The size will apply to all sectors between the listed address and the next address
* in the list.
* The last pair in the list will have sectors starting at that address and ending
* at address flash_start + flash_size.
*/
static const sector_info_t sectors_info[] = {
    {0x30000000, 0x00001000},
};

static const program_target_t flash = {
    0x20000033,                         // .init
    0x2000005f,                         // .uninit
    0x20000081,                         // .erase_chip
    0x200000ad,                         // .erase_sector
    0x200000f1,                         // .program_page
    0x0,                                // .verify
    {                                   // .sys_call_s
        0x20000001,                     // .breakpoint   : start of blob + 1
        0x2000038C,                     // .static_base  : blob start + header + rw data offset
        0x20002800                      // .stack_pointer
    },
    0x20000000 + 0x00003000,            // mem buffer location
    0x20000000,                         // location to write prog_blob in target RAM
    sizeof(DAPLINK_RT1170_flash_prog_blob), // prog_blob size
    DAPLINK_RT1170_flash_prog_blob,     // address of prog_blob
    0x00000100                          // .algo_flags: ram_to_flash_bytes_to_be_written
};
